// integral.js
//获取应用实例  
var app = getApp()
Page({
  data: {
    /** 
        * 页面配置 
        */
    winWidth: 0,
    winHeight: 0,
    // tab切换  
    currentTab: 0,
    catalogSelect: 0,//判断是否选中
    _num: 8,
    pasnumb: [2, 4, 6, 8, 10],
    score: 8,
    str: '“很好”',
    tabArr: { "curHdIndex": 4 },
    textat: ''
  },
  // chooseCatalog: function (data) {
  //     var that = this;
  //     var Select = that.select;
  //     that.setData({//把选中值放入判断值
  //         catalogSelect: data.currentTarget.dataset.select,

  //     })
  // },
  // 星级评价
  chooseicon: function (e) {
    var str
    var strnumber = e.target.dataset.id;
    var nub = e.target.dataset.numb;
    var _obj = {};
    _obj.curHdIndex = strnumber;

    if (strnumber == 1) {
      str = '"太差了"';
    }
    if (strnumber == 2) {
      str = '"不好"';
    }
    if (strnumber == 3) {
      str = '"一般"';
    }
    if (strnumber == 4) {
      str = '"很好"';
    }
    if (strnumber == 5) {
      str = '"非常好"';
    }

    console.log(e.target.dataset.numb)
    this.setData({
      tabArr: _obj,
      score: e.target.dataset.numb,
      str: str
    });

  },
  click: function (e) {
    console.log(e.target.dataset.num)
    this.setData({
      _num: e.target.dataset.num
    })
  },
  onLoad: function (options) {
    var that = this
    that.setData({
      isHide: true,
      options: options
    })
  },
  tags: function (e) {
    var temp = this.data.tag;
    for (let i = 0; i < temp.length; i++) {
      if (e.currentTarget.dataset.id == temp[i].id) {
        temp[i].selected = !temp[i].selected;
      }
    }
    this.setData({
      tag: temp,
      tags: e.currentTarget.dataset.id
    })
    console.log(e.currentTarget.dataset.id)
  },
  textat: function (e) {
    this.setData({
      textat: e.detail.value
    })
    console.log(e.detail.value)
  },
  // submit:function(e){
  //   var that = this,
  //   this.setData({

  //   })
  // },
  onShow: function () {
    var app = getApp()
    var that = this;
    var uid = wx.getStorageSync('uid');
    var status = that.data.status
    // console.log(that.data.currentTab)
    // console.log(uid)
    wx.request({
      url: app.globalData.host + '&g=App&m=User&a=ogShow',
      data: {
        id: that.data.options.id,
        uid: uid,
        status: that.data.status
      },
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        console.log(res.data)
        var ad = res.data.ad;
        that.setData({
          tag: res.data.comments_tag,
          goods_img: res.data.goods_img,
          goods_attr: res.data.goods_attr,
          goods_name: res.data.goods_name
        })
      }
    })
    that.setData({
      isHide: 1,
    })
  },
  sub: function (e) {
    var app = getApp()
    var that = this;
    var uid = wx.getStorageSync('uid');
    var evaluate = that.data.textat
    var tag = that.data.tag
    var tags = ''
    var tagkk = 0
    for (let i = 0; i < tag.length; i++) {
      if (tag[i].selected) {
        tags = tags + (tagkk ? ',' : '') + tag[i].id
        tagkk++
      }
    }
    console.log(that.data.textat)
    // var score = e.target.dataset.numb
    var elength = evaluate.length
    console.log(elength)
    console.log(tags)
    console.log(that.data.score)
    if (elength < 8) {
      wx.showModal({
        title: '提示',
        content: '请填写完整资料',
        showCancel: false
      })
    } else {
      wx.request({
        url: app.globalData.host + '&g=App&m=User&a=saveOg',
        data: {
          id: that.data.options.id,
          uid: uid,
          comment_tag: tags,
          evaluate: that.data.textat,
          evaluate_lv: that.data.score
        },
        header: {
          'content-type': 'application/json'
        },
        success: function (res) {
          if (res.data.status == 1) {         
            wx.showToast({
              title: '评介成功',
              icon: 'loading',
              duration: 1500,
              complete: function (res1) {
                               
              }
            })
            setTimeout(function () {
              wx.navigateTo({
                url: '/page/member/evaluate?currentTab=1'
              })
            }, 1200) 
            return false;           
          } else {
            wx.showModal({
              title: '提示',
              content: res.data.info,
              showCancel: false
            })
          }
        }
      })

    }

    that.setData({
      isHide: 1,
    })
  }
}) 
